/**
 * Copyright (C) 2008 Motudo Studio
 * 
 * @author game@motudo.com (motudo lin)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package motudo.screen.domain;

import java.util.Calendar;
import java.util.GregorianCalendar;


public class FourNextTimer implements INextTimerService {
	
	private int count = 0;
	
	private boolean fullScreenFlag = true;
	
	private int lastResult = 0;
	
	private long lastTime = 0;
	
	public static final int[] TIME_ARR = {28*60*1000,2*60*1000,22*60*1000,8*60*1000,};
	//public static final int[] TIME_ARR = {2*60*1000,1*60*1000,3*60*1000,2*60*1000,};

	
	public FourNextTimer(){
		this.lastResult = TIME_ARR[0];
		Calendar cal = new GregorianCalendar();
		lastTime = cal.getTimeInMillis() + this.lastResult;	
	}

	@Override
	public int nextMillSecs() {
		fullScreenFlag = !fullScreenFlag;
		int result = TIME_ARR[count++%TIME_ARR.length];
		this.lastResult = result;
		Calendar cal = new GregorianCalendar();
		lastTime = cal.getTimeInMillis() + this.lastResult;	
		//System.out.println("NEXT " + result + ", FS : " + fullScreenFlag);
		return result;
	}

	@Override
	@Deprecated
	public boolean isFullScreen() {
		return fullScreenFlag;
	}

	@Override
	public int getNextMins() {
		return lastResult/60/1000;
	}

	@Override
	public long getNextDateTime() {
		return this.lastTime;
	}

	@Override
	public String getInfo() {
		// xx % / xx mins
		float percent = getProgressPercent();
		String result = String.format("%.1f %% / %d mins", percent,this.getNextMins());	
		return result;
	}

	@Override
	public float getProgressPercent() {
		Calendar cal = new GregorianCalendar();
		long diff = lastTime - cal.getTimeInMillis();
		float percent = (lastResult - diff) * 100f / lastResult;
		return percent;
	}

}
